package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.EventActionDTO;
import cn.com.blueInfo.bpm.template.response.EventActionVO;
import cn.com.blueInfo.bpm.template.service.EventActionService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 事件动作表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "事件动作 接口")
@RestController
@RequestMapping("/template/eventAction")
public class EventActionController extends BaseController {

    @Autowired
    private EventActionService eventActionService;

    /**
     * 新建事件动作
     * @param eventActionDTO 事件动作参数
     * @return ResultInfo
     */
    @Operation(summary = "新增事件动作")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createEventAction(
            @Validated({Create.class, Default.class}) @RequestBody EventActionDTO eventActionDTO) {
        return eventActionService.addEventAction(eventActionDTO);
    }

    /**
     * 批量新建事件动作
     * @param eventActionDTOList 事件动作参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建事件动作")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateEventAction(
            @Validated({Create.class, Default.class}) @RequestBody List<EventActionDTO> eventActionDTOList) {
        return eventActionService.batchAddEventAction(eventActionDTOList);
    }

    /**
     * 根据ID删除事件动作
     * @param eventActionId 事件动作ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除事件动作")
    @DeleteMapping("/removeInfo/{eventActionId}")
    public ResultInfo<Integer> deleteEventActionById(
            @Parameter(name = "ID") @PathVariable Long eventActionId) {
        return eventActionService.removeEventAction(eventActionId);
    }

    /**
     * 批量根据ID删除事件动作
     * @param eventActionIdList 事件动作ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除事件动作")
    @DeleteMapping("/removeInfoList/{eventActionIdList}")
    public ResultInfo<Integer> batchDeleteEventActionById(
            @Parameter(name = "ID") @PathVariable List<Long> eventActionIdList) {
        return eventActionService.batchRemoveEventAction(eventActionIdList);
    }

    /**
     * 根据ID全量更新事件动作
     * @param eventActionId 事件动作ID
     * @param eventActionDTO 事件动作参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新事件动作")
    @PutMapping("/modifyInfo/{eventActionId}")
    public ResultInfo<Integer> updateEventActionFull(
            @Parameter(name = "ID") @PathVariable Long eventActionId,
            @Validated({Update.class, Default.class}) @RequestBody EventActionDTO eventActionDTO) {
        validateUpdateId(eventActionId, eventActionDTO.getId());
        return eventActionService.modifyEventAction(eventActionDTO);
    }

    /**
     * 根据ID部分更新事件动作
     * @param eventActionId 事件动作ID
     * @param eventActionUpdatePartialDTO 事件动作参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新事件动作")
    @PatchMapping("/modifyPartialInfo/{eventActionId}")
    public ResultInfo<Integer> updateEventActionPartial(
            @Parameter(name = "ID") @PathVariable Long eventActionId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            EventActionDTO.UpdatePartialDTO eventActionUpdatePartialDTO) {
        validateUpdateId(eventActionId, eventActionUpdatePartialDTO.getId());
        return eventActionService.modifyEventActionPartial(eventActionUpdatePartialDTO);
    }

    /**
     * 根据ID查询事件动作
     * @param eventActionId 事件动作ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询事件动作")
    @GetMapping("/getInfo/{eventActionId}")
    public ResultInfo<EventActionVO> getEventActionById(
            @Parameter(name = "ID") @PathVariable Long eventActionId) {
        return eventActionService.queryEventActionById(eventActionId);
    }

    /**
     * 分页查询事件动作
     * @param eventActionQueryDTO 事件动作参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询事件动作")
    @GetMapping("/getInfos")
    public ResultInfo<Page<EventActionVO>> getEventActionPage(
            @Validated EventActionDTO.QueryDTO eventActionQueryDTO) {
        return eventActionService.queryEventActionPage(eventActionQueryDTO);
    }

    /**
     * 根据条件查询事件动作
     * @param eventActionQueryDTO 事件动作参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询事件动作")
    @GetMapping("/getInfoList")
    public ResultInfo<List<EventActionVO>> getEventActionList(
            @Validated EventActionDTO.QueryDTO eventActionQueryDTO) {
        return eventActionService.queryEventActionList(eventActionQueryDTO);
    }

}
